#include "timer.h"

void TIM3_Int_Init(u16 arr, u16 psc)
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);		// 时钟使能
	
	// 定时器TIM3初始化
	TIM_TimeBaseStructure.TIM_Prescaler = psc;	// 预分频值
	TIM_TimeBaseStructure.TIM_Period = arr;			// 自动重装载值
	TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;	// 向上计算模式
	TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
	
	
	// 中断优先级NVIC设置
	NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;			// TIM5中断
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 4; // 先抢占优先级4
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	
	TIM_Cmd(TIM3,ENABLE);
}

